#include "checkin.h"
#include "ui_checkin.h"
#include "admininfo.h"
#include"studentinfo.h"
#include"teacherinfo.h"
#include <QDebug>
#include"login.h"
#include<QString>
#include<QSqlDatabase>
#include<QSqlQueryModel>
#include<QAbstractItemModel>

Checkin::Checkin(QObject *parent) :
    QObject(parent),ui(new Ui::Checkin)
{
    m_loginW = new Login;
    connect(m_loginW, SIGNAL(signalAdminLoginSuccess(AdminInfo)),
            this, SLOT(slotAdminLoginSuccess(AdminInfo)));
    connect(m_loginW, SIGNAL(signalStudentLoginSuccess(StudentInfo)),
            this, SLOT(slotStudentLoginSuccess(StudentInfo)));
    connect(m_loginW, SIGNAL(signalTeacherLoginSuccess(TeacherInfo)),
            this, SLOT(slotTeacherLoginSuccess(TeacherInfo)));
}

Checkin::~Checkin()
{
    delete ui;
    delete m_loginW;
}

 void Checkin::initWindow()
  {
      ui->lineEdit_checkin_classid->setPlaceholderText(tr("classid"));
  }

 void Checkin::show(void)
 {
     this->show();
 }

void Checkin::slotAdminLoginSuccess(AdminInfo info)
{
    m_admininfo = ExecSQL::selectStudentInfo(info.getID());
    m_admininfo.updateAdminInfo(info);
    m_admininfo.display();
    this->showLoginW();
}

void Checkin::slotStudentLoginSuccess(StudentInfo info)
{
    qDebug()<<"m_student";
    m_studentinfo = ExecSQL::selectStudentInfo(info.getID());
    m_studentinfo.updateStudentInfo(info);
    m_studentinfo.display();
    this->showLoginW();
}

void Checkin::slotTeacherLoginSuccess(TeacherInfo info)
{
    m_teacherinfo = ExecSQL::selectTeacherInfo(info.getID());
    m_teacherinfo.updateTeacherInfo(info);
    m_teacherinfo.display();
    this->showLoginW();
}

void Checkin::showLoginW(void)
{
    m_loginW->show();
}


